/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BookListsPage.java
 *
 * Created on 06 29, 12, 12:17:39 PM
 */
package Display;

import javax.swing.JOptionPane;

/**
 *
 * @author Aeron
 */
public class BookListsPageFinal extends javax.swing.JFrame {

    /** Creates new form BookListsPage */
    public BookListsPageFinal() {
        initComponents();
        this.setTitle("Books");
        this.setSize(698,488);
        this.setResizable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        section = new javax.swing.JComboBox();
        searchbox = new javax.swing.JTextField();
        search = new javax.swing.JButton();
        add = new javax.swing.JButton();
        edit = new javax.swing.JButton();
        delete = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        booktable = new javax.swing.JTable();
        borrow = new javax.swing.JButton();
        reserve = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel2.setFont(new java.awt.Font("Garamond", 1, 18)); // NOI18N
        jLabel2.setText("List of Books");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(80, 50, 130, 30);

        section.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        section.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ISBN", "Title", "Author", "Genre" }));
        getContentPane().add(section);
        section.setBounds(220, 50, 80, 30);

        searchbox.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        getContentPane().add(searchbox);
        searchbox.setBounds(310, 50, 240, 30);

        search.setBackground(java.awt.Color.white);
        search.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        search.setText("Search");
        search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchActionPerformed(evt);
            }
        });
        getContentPane().add(search);
        search.setBounds(560, 50, 90, 30);

        add.setBackground(java.awt.Color.white);
        add.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        add.setText("Add");
        add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addActionPerformed(evt);
            }
        });
        getContentPane().add(add);
        add.setBounds(40, 380, 90, 30);

        edit.setBackground(java.awt.Color.white);
        edit.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        edit.setText("Edit");
        edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editActionPerformed(evt);
            }
        });
        getContentPane().add(edit);
        edit.setBounds(140, 380, 90, 30);

        delete.setBackground(java.awt.Color.white);
        delete.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        delete.setText("Delete");
        delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteActionPerformed(evt);
            }
        });
        getContentPane().add(delete);
        delete.setBounds(460, 380, 90, 30);

        booktable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "ISBN", "Title", "Author", "Genre"
            }
        ));
        jScrollPane1.setViewportView(booktable);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(40, 90, 620, 280);

        borrow.setBackground(java.awt.Color.white);
        borrow.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        borrow.setText("Borrow");
        borrow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                borrowActionPerformed(evt);
            }
        });
        getContentPane().add(borrow);
        borrow.setBounds(240, 380, 90, 30);

        reserve.setBackground(java.awt.Color.white);
        reserve.setFont(new java.awt.Font("Garamond", 0, 14)); // NOI18N
        reserve.setText("Reserve");
        reserve.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reserveActionPerformed(evt);
            }
        });
        getContentPane().add(reserve);
        reserve.setBounds(560, 380, 90, 30);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/MLFbgWhite1.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 700, 500);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editActionPerformed
// TODO add your handling code here:
       
        //nageeror kapag null value ung laman ng table so assume n lng ntin na may laman?
        
        int row = booktable.getSelectedRow();
        String getbook = (String) booktable.getValueAt(0, row);
        
      int reply = JOptionPane.showConfirmDialog(null, "", "Are you sure you want to edit this book?", JOptionPane.YES_NO_CANCEL_OPTION);
       
      if(reply == JOptionPane.YES_OPTION)
      {
        this.setVisible(false);
        new AddEditPageFinal().setVisible(true);
      }
}//GEN-LAST:event_editActionPerformed

    private void borrowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_borrowActionPerformed
        // TODO add your handling code here:
        
           //nageeror kapag null value ung laman ng table so assume n lng ntin na may laman?
        
        int row = booktable.getSelectedRow();
        String getbook = (String) booktable.getValueAt(0, row);
        
      int reply = JOptionPane.showConfirmDialog(null, "", "Are you sure you want to borrow this book?", JOptionPane.YES_NO_CANCEL_OPTION);
       
      if(reply == JOptionPane.YES_OPTION)
      {
        //database part
          
         JOptionPane.showMessageDialog(null, "Book is borrowed successfully.");
      }
    }//GEN-LAST:event_borrowActionPerformed

    private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
        // TODO add your handling code here:
        
        
       this.setVisible(false);
       new AddEditPageFinal().setVisible(true);
        
    }//GEN-LAST:event_addActionPerformed

    private void deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteActionPerformed
        // TODO add your handling code here:
           //nageeror kapag null value ung laman ng table so assume n lng ntin na may laman?
        
        int row = booktable.getSelectedRow();
        //value in the table(selected)
        String getbook = (String) booktable.getValueAt(0, row);
        
      int reply = JOptionPane.showConfirmDialog(null, "", "Are you sure you want to return this book?", JOptionPane.YES_NO_CANCEL_OPTION);
       
      if(reply == JOptionPane.YES_OPTION)
      {
        //database part
          
         JOptionPane.showMessageDialog(null, "Book is deleted successfully.");
      }
        
        
    }//GEN-LAST:event_deleteActionPerformed

    private void reserveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reserveActionPerformed
        // TODO add your handling code here:
        
         //nageeror kapag null value ung laman ng table so assume n lng ntin na may laman?
        
        int row = booktable.getSelectedRow();
        //value in the table(selected)
        String getbook = (String) booktable.getValueAt(0, row);
        
      int reply = JOptionPane.showConfirmDialog(null, "", "Are you sure you want to reserve this book?", JOptionPane.YES_NO_CANCEL_OPTION);
       
      if(reply == JOptionPane.YES_OPTION)
      {
        //database part
          
         JOptionPane.showMessageDialog(null, "Book is reserved successfully.");
      }
        
    }//GEN-LAST:event_reserveActionPerformed

    private void searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchActionPerformed
        // TODO add your handling code here:
        
        
       //check if textfield has value
        if(searchbox.getText().isEmpty())
            JOptionPane.showMessageDialog(null, "Please input text in the search field.");
        else
        {
            //database part
        }
                
        
    }//GEN-LAST:event_searchActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BookListsPageFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BookListsPageFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BookListsPageFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BookListsPageFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new BookListsPageFinal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton add;
    private javax.swing.JTable booktable;
    private javax.swing.JButton borrow;
    private javax.swing.JButton delete;
    private javax.swing.JButton edit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton reserve;
    private javax.swing.JButton search;
    private javax.swing.JTextField searchbox;
    private javax.swing.JComboBox section;
    // End of variables declaration//GEN-END:variables
}
